Permutation in String

Medium

Extra practice. This problem has no walkthrough slides. Try solving it with the pattern template on your own, and lean on the hints if you get stuck.

Question

You get two strings of lowercase letters, s1 and s2. Return true if some contiguous stretch of s2 uses exactly the same letters as s1, just possibly in a different order. Otherwise return false.

Input: s1 = "ab", s2 = "eidbaooo"

Output: true

The stretch "ba" starting at index 3 uses exactly the letters in "ab", just in a different order.

Input: s1 = "ab", s2 = "eidboaoo"

Output: false

No two-letter stretch of s2 uses exactly one "a" and one "b".

Input: s1 = "adc", s2 = "dcda"

Output: true

The stretch "cda", the last three letters of s2, uses exactly the letters in "adc".

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

Which of these words contains a stretch of letters that uses exactly the same letters as "abc"?
"muckrake"
"bracket"
"cabinet"
"camel"

Take a moment to understand the problem and think of your approach before you start coding.